//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.framework.web.codetable;

import java.sql.SQLException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"/codetable"})
public class CodetableController {
    @Resource
    private CodetableService service;

    public CodetableController() {
    }

    @RequestMapping(
        value = {"/gotoList"},
        method = {RequestMethod.GET}
    )
    public ModelAndView gotoList(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/framework/codetable/list");
        mav.addObject("codetable", request.getParameter("codetable"));
        mav.addObject("codelevel", request.getParameter("codelevel"));
        return mav;
    }

    @RequestMapping(
        value = {"/gotoListManager"},
        method = {RequestMethod.GET}
    )
    public String gotoListManager(HttpServletRequest request) {
        return "/framework/codetable/listmanager";
    }

    @RequestMapping(
        value = {"/queryList"},
        method = {RequestMethod.POST}
    )
    @ResponseBody
    public String queryList(CodetableModel model, HttpServletRequest request) {
        return this.service.queryList(model);
    }

    @RequestMapping(
        value = {"/queryManagerList"},
        method = {RequestMethod.POST}
    )
    @ResponseBody
    public String queryManagerList(CodeTableManagerModel model, HttpServletRequest request) {
        if (model.getCodetable() != null && model.getCodetable().indexOf("_") > -1) {
            model.setCodetable(model.getCodetable().replaceAll("_", "\\\\_"));
        }

        return this.service.queryManagerList(model);
    }

    @RequestMapping(
        value = {"/gotoAdd"},
        method = {RequestMethod.GET, RequestMethod.POST}
    )
    public String gotoAdd(HttpServletRequest request) {
        request.setAttribute("codetable", request.getParameter("codetable"));
        return "/framework/codetable/add";
    }

    @RequestMapping(
        value = {"/gotoManagerAdd"},
        method = {RequestMethod.GET, RequestMethod.POST}
    )
    public String gotoManagerAdd(HttpServletRequest request) {
        return "/framework/codetable/addmanager";
    }

    @RequestMapping(
        value = {"/doAdd"},
        method = {RequestMethod.POST}
    )
    @ResponseBody
    public String doAdd(CodetableModel model) {
        try {
            return this.service.add(model) ? "success" : "failure";
        } catch (SQLException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    @RequestMapping(
        value = {"/gotoEdit"},
        method = {RequestMethod.GET, RequestMethod.POST}
    )
    public ModelAndView gotoEdit(HttpServletRequest request) {
        String id = request.getParameter("id");
        String codetable = request.getParameter("codetable");
        CodetableModel model = new CodetableModel();
        model.setCode(id);
        model.setCodetable(codetable);
        model = this.service.getInfoById(model);
        ModelAndView mav = new ModelAndView("/framework/codetable/edit");
        mav.addObject("model", model);
        return mav;
    }

    @RequestMapping(
        value = {"/doEdit"},
        method = {RequestMethod.POST}
    )
    @ResponseBody
    public String doEdit(CodetableModel model) {
        return this.service.edit(model) > 0 ? "success" : "failure";
    }

    @RequestMapping(
        value = {"/gotoDelete"},
        method = {RequestMethod.POST, RequestMethod.GET}
    )
    @ResponseBody
    public String gotoDelete(HttpServletRequest request) {
        String ids = request.getParameter("ids");
        System.out.println("==============================" + ids);
        String codetable = request.getParameter("codetable");
        CodetableModel model = new CodetableModel();
        model.setCode(ids);
        model.setCodetable(codetable);
        this.service.delete(model);
        return "success";
    }

    @RequestMapping(
        value = {"/gotoView"},
        method = {RequestMethod.GET}
    )
    public ModelAndView gotoView(HttpServletRequest request) {
        String id = request.getParameter("id");
        String codetable = request.getParameter("codetable");
        CodetableModel model = new CodetableModel();
        model.setCode(id);
        model.setCodetable(codetable);
        model = this.service.getInfoById(model);
        ModelAndView mav = new ModelAndView("/framework/codetable/view");
        mav.addObject("model", model);
        return mav;
    }

    @RequestMapping(
        value = {"/codeSelect"},
        produces = {"application/json; charset=utf-8"},
        method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public String codeSelect(HttpServletRequest request, HttpServletResponse response) {
        String codetable = request.getParameter("codetable");
        String parentcode = request.getParameter("parentcode");
        String showtype = request.getParameter("showtype");
        String pinyin = request.getParameter("pinyin");
        return showtype == null ? this.service.deal(codetable, parentcode, response, pinyin) : this.service.dealComboTree(codetable, parentcode, response);
    }
}
